<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>确认订单</title>
    <link rel="stylesheet" href="{:C('__STATIC__')}{$theme}/Static/{:C('css')}/total.css" />
    <style>
        .pay-type {
            float:right;
            margin:0 0.3rem 0 0;
            height:100%;
            border:0;
            color:#666;
            text-align: right;
        }
    </style>
</head>
<body>

<div class="left-manage">
    <div class="white">
        <a class="white-li">
            <p>配送方式</p>
            <volist name="express" id="express">
                <div class="white-top">
                    <span class="express_name">{$express['e_name']}</span>
                    <input name="kt" class="white-ipt" type="radio" value="{$express['id']}">
                </div>
            </volist>
            <input type="hidden" name="send_type" value="0" id="send_type"/>
        </a>
    </div>
    <div class="main"></div>

    <div id="header">
        <div class="header">
            <h1 class="tit">确认订单</h1>
        </div>
    </div>

    <div class="ddxq-a">
        <div class="ddxq-aa">
            <img src="{:C('__STATIC__')}{$theme}/Static/img/ddxq-ad.jpg" class="ddxq-img1">
            <div class="ddxq-right" id="agent_address">
                <div class="ddxq-right-1">
                    <span id="gets_user"></span><span id="gets_mobile"></span>
                </div>
                <div class="ddxq-right-2">
                    <span>收货地址：</span><a id="gets_area"></a>
                </div>
            </div>
        </div>
    </div>
    <input class="address_id" value="" type="hidden"/>

    <div class="ddxq-b qrdd-zong">
        <div class="ddxq-bb qrdd-bb">
            <p class="ddxq-p1">元典科技</p>
            <volist name="goods" id="goods">
                <div class="ddxq-div1">
                    <img src="{$goods['img']}">
                    <div class="ddxq-title">
                        <p>{$goods['g_name']}</p>
                        <span class="stb">{$goods['spec_str']}</span>
                        <p class="ddqx-title-p"><span>¥ {$goods['comprice']}元</span>
                            <span>×{$goods['good_num']}</span>
                            </p>
                    </div>
                </div>
            </volist>
            <div class="ddxq-div3">
                <p>配送方式：
                    <a class="qrdd-kuaidi" id="yunfei">请选择快递&nbsp;&nbsp;
                        <img src="{:C('__STATIC__')}{$theme}/Static/img/tj.jpg">
                    </a>
                </p>
            </div>
            <div class="ddxq-div3">
                <p>邮寄费用：
                    <a class="qrdd-kuaidiv">
                        0<span>元</span>
                    </a>
                </p>
            </div>

            <div class="ddxq-div3 qrdd-liuyan">
                <p>买家留言：</p>
                <textarea name="message"></textarea>
            </div>
            <div class="ddxq-div3 nonexian">
                <p>共
                    <input class="good_status" value="{$status}" type="hidden">
                    <input class="good_ida" value="{$good_ida}" type="hidden">
                    <input class="good_num" value="{$good_num}" type="hidden">
                    <input class="spec_str" value="{$spec_str}" type="hidden">
                    <input type="hidden" value="1" id="is_freight">
                    <a class="ddxq-gray">{$totalsum}</a>件商品&nbsp;&nbsp;小计：
                    <a class="ddxq-red">￥{$count}元</a>
                </p>
            </div>
        </div>
    </div>
    <div class="ddxq-c qrdd-cc">
        <div class="qrdd-left">
            <p>合计金额：¥
                <a class="count">{$count}元</a>
                <input class="truecount" type="hidden" value="{$count}">
                <input class="delivery_type" type="hidden" value="2">
                <input class="good_aid" type="hidden" value="{$good_aid}">
                <input id="p_sum" type="hidden" value="0">
            </p>
        </div>
        <div class="qrdd-right">
            <a id="save">确认订单</a>
            <a id="show" style="display: none">确认订单中...</a>
        </div>
    </div>
</div>
<div class="manage-site">
    <div id="headerb">
        <div class="header">
            <h1 class="tit">收货地址</h1>
            <p class="goback">
                <a class="go-sure return">返回</a>
            </p>
			<a class="add-addres">新增</a>
        </div>
    </div>

    <div class="address_site">
        <foreach name="address" item="inv">
            <div class="shdz-a address-sigle" onclick="get_address1( '{$inv[address_id]}');">
                <p class="shdz-p1"><a>{$inv['consignee']}</a><a class="a-right">{$inv['mobile']}</a></p>
                <p class="shdz-p2">{$inv['province']} {$inv['city']} {$inv['area']}  {$inv['detail_address']}</p>
            </div>
        </foreach>
    </div>

    <div class="append-site">
        <div id="headerc">
            <div class="header">
                <h1 class="tit">请先添加地址</h1>
                <p class="goback">
                    <a class="go-manage return">返回</a>
                </p>
            </div>
        </div>
        <div class="tjxdz-a">
            <div class="tjxdz-a1">
                <span>收货人：</span>
                <input type="text" id="s_user"/>
            </div>
            <div class="tjxdz-a1">
                <span>联系电话：</span>
                <input type="text" id="s_mobile" onKeyUp="this.value=this.value.replace(/[^\d.]/g,'')" onpaste="this.value=this.value.replace(/[^\d.]/g,'')"/>
            </div>
            <div class="tjxdz-a1">
                <span>所在地区：</span>
                <span class="content-block">请选择</span>
                <div class="content-chose" data-toggle="distpicker">
                    <select id="provice"></select>
                    <select id="city"></select>
                    <select id="area"></select>
                </div>
            </div>
            <div class="tjxdz-a1 tjxdz-a4">
                <textarea placeholder="请填写详细地址" id="s_area" style="padding: 0"></textarea>
            </div>
            <div class="person-form"><span id="add_btn">添加</span></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function resize() {
        var clientWidth = document.documentElement.clientWidth;
        document.documentElement.style.fontSize = 100 * (clientWidth / 750) + 'px';
    }
    resize();
    window.addEventListener('resize', resize);
</script>
<script type="text/javascript" src="{:C('__STATIC__')}{$theme}/Static/js/jquery-2.1.4.min.js" ></script>
<script type="text/javascript" src="__PUBLIC__/Admin/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.data.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/distpicker.js"></script>
<script type="text/javascript" src="__PUBLIC__/Admin/static/distpicker/js/main.js"></script>
<script>
    $(function () {
        $("#add_btn").click(function () {
            //拼接规格和规格的值
            var s_user = $("#s_user").val();
            var s_mobile = $("#s_mobile").val();
            var provice = $("#provice").val();
            var city = $("#city").val();
            var area = $("#area").val();
            var s_area = $("#s_area").val();
            if(!s_user || !s_mobile || !provice || !city || !area || !s_area){
                layer.msg('信息填写不完整！', {time: 1500});
                return false;
            }
            $.ajax({
                type: 'post',
                url:"{:U('Setting/address_add')}",
                data: {
                    tel: s_mobile,
                    get_user: s_user,
                    addre:s_area,
                    provice: provice,
                    city: city,
                    area: area
                },
                success: function(msg) {
                    if(msg.status == "success") {
                        get_address( msg.address_id) ;
                        layer.msg('添加成功！', {time: 1500});
                        setTimeout(function(){
                            location.reload(true);
                        }, 1000);
                    }else if(msg.status == "error"){
                        layer.msg(msg.msg, {time: 1500});
                    }
                }
            });
        })

        $('#yunfei').click(function () {
            var info = "{$express}";
            if(info ==''){
                layer.msg("卖家未设置快递",{time:1500});return false;
            }
            $('.main').addClass('ones');
            $('.white').addClass('ones');
            $(".main").addClass("tts");
        });

        // 支付费用计算
//        $('#p_type').change(function (){
//            var p_type = $(this).val();
//            var count_amt = "{$count}";
//            var freight = parseFloat($('#p_sum').val());
//            if(!p_type){
//                $("#p_fee").val(0);
//                $count_amt = freight + parseFloat(count_amt);
//                $('.count').text($count_amt);
//                return false;
//            }
//            $.ajax({
//                url: "{:U('Order/sum_pay_fee')}",
//                type: 'post',
//                data: {
//                    pay_type :p_type,
//                    pay_amt :"{$count}",
//                },
//                success: function (msg) {
//                    $count_amt = freight + parseFloat(msg.amt) + parseFloat(count_amt);
//                    $('.count').text($count_amt);
//                    $("#p_fee").val(msg.amt);
//                }
//            });
//        });

        $(".main").click(function () {
            $('.main').removeClass('ones');
            $('.white').removeClass('ones');
            $(".main").removeClass("tts");
            $(".boxt").css('z-index', '100001');
        });

        $(".white-ipt").click(function () {
            $send_type = $(this).val();
            $("#send_type").val($send_type);
            $pdd = $(this).parents('.white-top').find('.express_name').text();
            $('#yunfei').text($pdd);
            $('.main').removeClass('ones');
            $('.white').removeClass('ones');
            $(".main").removeClass("tts");
            my_freight();
        });

        $('#save').click(function () {
            var message = $('textarea[name="message"]').val();
            var good_type = $(".good_status").val();//整箱或单件
            var good_id = $('.good_ida').val();
            var num = $('.good_num').val();
            var address_id = $('.address_id').val();
            var is_freight = $('#is_freight').val();
            var delivery_type = $('.delivery_type').val();
            var good_aid = $('.good_aid').val();
            var send_type = $("#send_type").val();
            var spec_str = $(".spec_str").val();

            if (is_freight == 1) {
                layer.msg('运费计算有误', {time:1500});
                return false;
            }

            $(this).hide();
            $("#show").show();
            $.ajax({
                url: "{:U('Order/place')}",
                type: 'post',
                data: {
                    message: message,
                    address_id: address_id,
                    good_type: good_type,
                    send_type: send_type,
                    good_id: good_id,
                    num: num,
                    // 加邮费的总价格
                    price: $('.count').text(),
                    freight_price: $('.qrdd-kuaidiv').text(),
                    delivery_type: delivery_type,
                    good_aid: good_aid,
                    spec_str: spec_str
                },
                beforeSend: function () {
                    layer.msg('提交订单中..', {time:1500});
                },
                success: function (msg) {
                    if (msg >0) {
                        layer.msg('提交订单成功!', {time: 1000});
                        setTimeout(function () {
                            window.location.href = "{:U('Order/order_confirm')}&id=" + msg;
                        }, 1000);
                    }
                    if(msg<0){
                        switch (msg){
                            case -1:layer.msg('商品信息有误', {time: 1500});break;
                            case -2:layer.msg('商品状态信息有误', {time: 1500});break;
                            case -3:layer.msg('商品数量至少为一件', {time: 1500});break;
                            case -4:layer.msg('规格信息有误', {time: 1500});break;
                            case -5:layer.msg('收货地址有误', {time: 1500});break;
                            case -6:layer.msg('邮费信息有误', {time: 1500});break;
                            case -7:layer.msg('总价合计有误', {time: 1500});break;
                            case -9:layer.msg('代理商品与普通商品不能一起购买', {time: 1500});break;
                        }
                        setTimeout(function () {
                            $("#save").show();
                            $("#show").hide();
                        },1500);
                    }
                    if(msg.status == -8){
                        layer.msg(msg.name, {time: 1500});
                        setTimeout(function () {
                            $("#save").show();
                            $("#show").hide();
                        },1500);
                    }
                }
            });
            //return false;
        });

        $(".content-block").click(function () {
            $(".content-block").hide();
            $(".content-chose").show();
        })

        $(".ddxq-aa").click(function () {
            $(".left-manage").addClass("left_manage");
            $(".manage-site").addClass("manage_site");
        });
        $(".go-sure").click(function () {
            $(".left-manage").removeClass("left_manage");
            $(".manage-site").removeClass("manage_site");
        });
        $(".add-addres").click(function () {
            $(".append-site").addClass("append_site");
        });
        $(".go-manage").click(function () {
            $(".append-site").removeClass("append_site");
        })
    });

    function my_freight() {
        $.ajax({
            url: "{:U('Order/freight')}",
            type: 'post',
            data: {
                freight_id: $('#send_type').val(),
                num: $('.good_num').val(),
                address_id: $('.address_id').val(),
                good_id: $('.good_ida').val(),
                good_type: $('.good_status').val()
            },
            success: function (msg) {
                if (msg == -1) {
                    $('.qrdd-kuaidiv').text('此收货地址没有设置运费');
                    $('#is_freight').val(1);
                    $('.count').text($('.truecount').val());
                    $("#p_sum").val(0);
                } else {
                    $res = parseFloat($('.truecount').val()) + parseFloat(msg);
                    $('.count').text($res);
                    $("#p_sum").val(parseFloat(msg));
                    $('.qrdd-kuaidiv').text(msg);
                    $('#is_freight').val(0);
                }
            }
        });
    }

    function get_address( id) {
        $.ajax({
            url: "{:U('Setting/ajax_get_address')}",
            type: 'post',
            data: {address_id: id},
            success: function (data) {
                $("#gets_user").text("");
                $("#gets_user").text(data.user);
                $("#gets_mobile").text("");
                $("#gets_mobile").text(data.mobile);
                $("#gets_area").text("");
                $("#gets_area").text(data.area);
                $(".address_id").val(data.address_id);

                my_freight()

            }
        });
    }
    get_address(0);
    function get_address1( id) {
        $(".left-manage").removeClass("left_manage");
        $(".manage-site").removeClass("manage_site");
        get_address( id);

//        my_freight()

    }
</script>
</body>
</html>
